package com.zhl.hdfs;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;
import java.net.URI;



public class HdfsClient {

    private FileSystem fs;

    @Before
    public void ini() throws Exception {
    //连接的集群nn地址
    URI uri = new URI("hdfs://hadoop102:8020");
    //创建一个配置文件
    Configuration conf = new Configuration();
    //设置用户名
    String user = "atguigu";

    //1.获取客户端对象
    fs = FileSystem.get(uri, conf, user);

    }

    @After
    public void close() throws IOException {
    //3.关闭客户端
    fs.close();

    }

    //创建目录
    @Test
    public void testmkdir() throws Exception {
        //2.创建一个文件夹
        fs.mkdirs(new Path("/xiyou/huaguoshan"));
    }




}
